package com.cuit.riskassessment.action.rm;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cuit.riskassessment.service.RmService;
import com.cuit.riskassessment.util.Result;
import com.cuit.riskassessment.vo.RmParam;
/**
 * rm 相关参数请求
 * @author Yang_Zhiqin-pc
 *
 */

@Controller
@RequestMapping(value="rm")
public class RmAction {

	@Autowired
	@Resource(name="rmService")
	private RmService rmService;
	/**
	 * 处理添加Ra的请求信息
	 * @param res  response 对象
	 * @param ra   ra参数信息
	 * @return     result 用于判断操作是否成功
	 */
	@RequestMapping(value="addorupdate")
	public @ResponseBody Object addOrUpdate(HttpServletResponse res,RmParam rm)
	{
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		if(this.rmService.addOrUpdateRu(rm))
		{
			result.setMessage("操作成功！");
			result.setSuccess(true);
		}else
		{
			result.setMessage("操作失败！");
			result.setSuccess(false);
		};
		
		return result;
	}
	
	/**
	 * 获取Ra信息
	 * @param res    response 对象
	 * @param projid 项目id
	 * @return       与项目id关联的ra信息
	 */
	@RequestMapping(value="get")
	public @ResponseBody Object getRm(HttpServletResponse res, @RequestParam(value="projid")int projid)
	{
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		Object obj = this.rmService.getRm(projid);
		if(obj == null)
		{
			result.setSuccess(false);
		}else
		{
			result.setSuccess(true);
			result.setOthers(obj);
		}
		
		return result;
	}
	
}
